package view
{
    import flash.display.*;
    import flash.geom.*;
    import flash.text.*;

    import view.Cell;

    public class Mission extends Sprite
    {
        public var missionRules:Array;
        public var missionRulesText:Array;

        public function Mission(x:Number, y:Number)
        {
            this.x = x;
            this.y = y;
            this.missionRules = new Array();
            this.missionRulesText = new Array();
            for(var i:int=0; i<6; i++)
            {
                var text:TextField = new TextField();
                text.x = 110 + 40*i;
                text.y = 0;
                text.text = ": 0";
                text.textColor = 0xFFFFFF;
                text.width = 50;
                text.height = 30;
                text.mouseEnabled = false;
                this.addChild(text);
                this.missionRulesText.push(text);
            }
        }

        public function setMissionRules(missionRules:Array):void
        {
            for(var i:int=this.missionRules.length-1; i>=0; i--)
            {
                this.missionRules.pop();
            }
            for(i=0; i<missionRules.length; i++)
            {
                this.missionRules.push(missionRules[i]);
            }
            this.display();
        }

        public function display():void
        {
            for(var i:int=0; i<6; i++)
            {
                if(i<this.missionRules.length)
                {
                    this.missionRulesText[i].text = ": " + this.missionRules[i].toString();
                }
                else
                {
                    this.missionRulesText[i].text = "";
                }
            }
        }

        public function isCompletedAll():Boolean
        {
            for(var i:int=0; i<this.missionRules.length; i++)
            {
                if(this.missionRules[i] > 0) return false;
            }
            return true;
        }

        public function complete(type:int, num:int):void
        {
            this.missionRules[type] -= num;
            if(this.missionRules[type] < 0)
            {
                this.missionRules[type] = 0;
            }
            this.display();
        }
    }
}
